//
//  ZTPhotoTableViewCell.m
//  CarTown
//
//  Created by xionghao on 15/8/27.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "ZTPhotoTableViewCell.h"
#define imgheight 200
#define kboder 8
#import <UIImageView+WebCache.h>
@implementation ZTPhotoTableViewCell

+(instancetype)cellWithTablView:(UITableView *)tablvew{
    ZTPhotoTableViewCell *cell=[tablvew dequeueReusableCellWithIdentifier:@"photo"];
    if (cell==nil) {
        cell=[[ZTPhotoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"photo"];
    }
    
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self==[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        CGFloat x=0;
        CGFloat y;
        CGFloat width=XHScreenwidth;
        CGFloat height=imgheight;
        for (int i=0; i<8; i++) {
            UIImageView *imageview=[[UIImageView alloc]init];
            y=(kboder+height)*i;
            imageview.frame=CGRectMake(x, y, width, height);
            imageview.contentMode=UIViewContentModeScaleAspectFill;
            imageview.tag=i;
            imageview.clipsToBounds=YES;
            [self.contentView addSubview:imageview];
            imageview.hidden=YES;
        }

    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setMode:(PhotoMode *)mode{
    _mode=mode;
    
}

-(void)setImgurls:(NSArray *)imgurls{
    _imgurls=imgurls;
    
    for (int i=0; i<8; i++) {
        UIImageView *imageview=self.contentView.subviews[i];
        if (i<_imgurls.count) {
            [imageview sd_setImageWithURL:[NSURL URLWithString:[NSString getImageURLstr:_imgurls[i]]] placeholderImage:[UIImage imageNamed:@"placehoder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
            imageview.hidden=NO;
        }else{
            imageview.hidden=YES;
        }
        
        
    }
}
@end
